package com.shudes.pt.db;

import java.util.*;

import junit.framework.*;

import org.hibernate.*;
import org.hibernate.criterion.*;

import com.shudes.pt.builder.*;
import com.shudes.pt.container.*;
import com.shudes.pt.pojo.*;
import com.shudes.util.*;


public class PojoTest extends TestCase {

	public PojoTest(String name) { 
		super(name);
	}
	
	public void testAll() {
//		this.selectBlindStructures();
//		this.selectPokerSites();
//		this.selectPlayer();
//		this.selectSession();
//		this.selectGame();
//		this.selectGamePlayer();
		this.selectGamePlayerDate(); 
	}

	public void selectGame() {
		SessionContext context;
		Session session;
		List games;
		
		context = new SessionContext();
		session = context.getSession();
		session.beginTransaction();
		games = 
			session.createCriteria(Game.class).add(Restrictions.idEq(new Long(300))).list();
		session.getTransaction().commit();
		System.out.println(Dumper.INSTANCE.dumpAllSideways(games));
	}
	
	public void selectSession() {
		SessionContext context;
		PlayerBuilder playerBuilder;
		PTSessionBuilder sessionBuilder;
		List<PTSession> sessions;
		Player p;
		Date on;
		
		on = Dates.create("08/07/2005"); 
		
		context = new SessionContext();
		
		playerBuilder = new PlayerBuilder(context); 
		p = playerBuilder.byName("poboys31");
		
		sessionBuilder = new PTSessionBuilder(context); 
		sessions = sessionBuilder.buildForDate(p, on);
		System.out.println(Dumper.INSTANCE.dumpAllSideways(sessions));
	}
	
	public void selectGamePlayer() {
		SessionContext context;
		Session session;
		List gps; 		
		List games;
		Game game; 
		
		context = new SessionContext();
		session = context.getSession();
		session.beginTransaction();
		games = 
			session.createCriteria(Game.class).add(Restrictions.idEq(new Long(300))).list();
		session.getTransaction().commit();
		
		game = (Game) games.get(0);

		session = context.getSession();
		session.beginTransaction();
//		gps = session.createCriteria(GamePlayer.class).add(Restrictions.eq("game", new Long(300))).list();
		gps = session.createCriteria(GamePlayer.class).add(Restrictions.eq("game", game)).list();
		session.getTransaction().commit();
		System.out.println(Dumper.INSTANCE.dumpAllSideways(gps));		
	}
	
	public void selectGamePlayerDate()
	{
		SessionContext context; 
		Player club305; 
		GamePlayerContainerMap map; 
		GamePlayerBuilder builder; 
		
		context = new SessionContext(); 
		
		club305 = new PlayerBuilder(context).byName("club305");
		System.out.println(club305.getScreenName());
		
		builder = new GamePlayerBuilder(context);
		map = builder.onDate(Dates.create("06-01-2007"));
		
//		List<Game> l = new GameBuilder(context).forOnDay(Dates.create("06-01-2007"));

	}
	
	public void selectPlayer() {
		SessionContext context;
		PlayerBuilder playerBuilder;
		Player p;
		
		context = new SessionContext();
		
		playerBuilder = new PlayerBuilder(context); 
		p = playerBuilder.byName("poboys31");
		
		System.out.println(Dumper.INSTANCE.dumpSideways(p));
		
//		sessionBuilder = new PTSessionBuilder(context); 
//		sessionBuilder.buildForDate(p, on);		

	}
	
	public void selectBlindStructures()
	{
		Session session=SessionUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List result = session.createQuery("from BlindStructure").list();
		session.getTransaction().commit();
		
		System.out.println(Dumper.INSTANCE.dumpAllFlat(result));
		
	}
	
	public void selectPokerSites()
	{
		Session session=SessionUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List result = session.createQuery("from PokerSite").list();
		session.getTransaction().commit();
		
		System.out.println(Dumper.INSTANCE.dumpAllFlat(result));
	}
	

	
	
}
